package org.yi.fc.interceptor;

import org.yi.fc.cache.GlobalCache;
import org.yi.fc.entity.FSysUser;

import com.jfinal.aop.Interceptor;
import com.jfinal.core.ActionInvocation;
import com.jfinal.core.Controller;

public class SessionInterceptor implements Interceptor {
	
	@Override
	public void intercept(ActionInvocation ai) {
		ai.invoke();
		
		Controller c = ai.getController();
		FSysUser user = c.getAttr("s_admin");
		
		if(c.getSession() == null || user == null){
			if(!c.getRequest().getRequestURI().startsWith("/admin/login")){
				//调试模式开启时不验证session
				if(!GlobalCache.config.getBoolean("debug")) {
					c.redirect("/admin/login");
				}
			}
		} else {
			ai.invoke();
		}
		
	}

}
